#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

class Solution
{
public:
    vector<int> countPairsOfConnectableServers(vector<vector<int>> &edges, int signalSpeed)
    {
        int n = 0;
        unordered_map<int, vector<pair<int, int>>> graph;
        for (auto edge : edges)
        {
            graph[edge[0]].push_back({edge[1], edge[2]});
            graph[edge[1]].push_back({edge[0], edge[2]});
            n = max(n, max(edge[0], edge[1]));
        }
        n++;
        vector<int> result(n, 0);
        for (int i = 0; i < n; i++)
        {
            int pre = 0;
            for (auto [node, weight] : graph[i])
            {
                int newNode = rr(node, i, weight, graph, signalSpeed);
                result[i] += newNode * pre;
                pre += newNode;
            }
        }
        return result;
    }

    int rr(int node, int parent, int value, unordered_map<int, vector<pair<int, int>>> &graph, int signalSpeed)
    {
        int res = 0;
        for (auto [next, weight] : graph[node])
        {
            if (next == parent)
                continue;
            res += rr(next, node, value + weight, graph, signalSpeed);
        }
        if (value % signalSpeed == 0)
            res++;
        return res;
    }
};

int main()
{
    cout << "Code3067" << endl;
    Solution s;
    return 0;
}